<form id="configForm" data-plugin="{$plugin_name}">
    {if !empty($config_fields)}
    {foreach $config_fields as $field}
    <div class="form-group">
        <label class="form-label">
            {$field.title}
            {if isset($field.required) && $field.required}
            <span style="color: #dc3545;">*</span>
            {/if}
        </label>

        {switch name="field.type"}
        {case value="text"}
        <input type="text" 
               name="{$field.name}" 
               value="{$plugin_config[$field.name] ?? ($field.default ?? $field.value ?? '')}" 
               class="form-control" 
               {if isset($field.required) && $field.required}required{/if}
               {if isset($field.placeholder)}placeholder="{$field.placeholder}"{/if}>
        {/case}

        {case value="textarea"}
        <textarea name="{$field.name}" 
                  class="form-control" 
                  rows="{$field.rows ?? 4}"
                  {if isset($field.required) && $field.required}required{/if}
                  {if isset($field.placeholder)}placeholder="{$field.placeholder}"{/if}>{$plugin_config[$field.name] ?? ($field.default ?? $field.value ?? '')}</textarea>
        {/case}

        {case value="select"}
        <select name="{$field.name}"
                class="form-control"
                {if isset($field.required) && $field.required}required{/if}>
            {if isset($field.options)}
            {foreach $field.options as $key => $label}
            <option value="{$key}"
                    {if ($plugin_config[$field.name] ?? ($field.default ?? $field.value ?? '')) == $key}selected{/if}>
                {$label}
            </option>
            {/foreach}
            {/if}
        </select>
        {/case}

        {case value="radio"}
        <div class="radio-group">
            {if isset($field.options)}
            {foreach $field.options as $key => $label}
            <label class="radio-label">
                <input type="radio"
                       name="{$field.name}"
                       value="{$key}"
                       {if ($plugin_config[$field.name] ?? ($field.default ?? $field.value ?? '')) == $key}checked{/if}
                       {if isset($field.required) && $field.required}required{/if}>
                {$label}
            </label>
            {/foreach}
            {/if}
        </div>
        {/case}

        {case value="checkbox"}
        <label class="checkbox-label">
            <input type="checkbox" 
                   name="{$field.name}" 
                   value="1"
                   {if ($plugin_config[$field.name] ?? ($field.default ?? $field.value ?? '')) == '1' || ($plugin_config[$field.name] ?? ($field.default ?? $field.value ?? '')) === true}checked{/if}>
            {$field.title}
        </label>
        {/case}

        {case value="number"}
        <input type="number" 
               name="{$field.name}" 
               value="{$plugin_config[$field.name] ?? ($field.default ?? $field.value ?? '')}" 
               class="form-control" 
               {if isset($field.required) && $field.required}required{/if}
               {if isset($field.min)}min="{$field.min}"{/if}
               {if isset($field.max)}max="{$field.max}"{/if}
               {if isset($field.step)}step="{$field.step}"{/if}
               {if isset($field.placeholder)}placeholder="{$field.placeholder}"{/if}>
        {/case}

        {case value="url"}
        <input type="url" 
               name="{$field.name}" 
               value="{$plugin_config[$field.name] ?? ($field.default ?? $field.value ?? '')}" 
               class="form-control" 
               {if isset($field.required) && $field.required}required{/if}
               {if isset($field.placeholder)}placeholder="{$field.placeholder}"{/if}>
        {/case}

        {case value="email"}
        <input type="email" 
               name="{$field.name}" 
               value="{$plugin_config[$field.name] ?? ($field.default ?? $field.value ?? '')}" 
               class="form-control" 
               {if isset($field.required) && $field.required}required{/if}
               {if isset($field.placeholder)}placeholder="{$field.placeholder}"{/if}>
        {/case}

        {case value="password"}
        <input type="password" 
               name="{$field.name}" 
               value="{$plugin_config[$field.name] ?? ($field.default ?? $field.value ?? '')}" 
               class="form-control" 
               {if isset($field.required) && $field.required}required{/if}
               {if isset($field.placeholder)}placeholder="{$field.placeholder}"{/if}>
        {/case}

        {default}
        <input type="text" 
               name="{$field.name}" 
               value="{$plugin_config[$field.name] ?? ($field.default ?? $field.value ?? '')}" 
               class="form-control" 
               {if isset($field.required) && $field.required}required{/if}
               {if isset($field.placeholder)}placeholder="{$field.placeholder}"{/if}>
        {/switch}

        {if isset($field.description)}
        <div class="form-text">{$field.description}</div>
        {/if}
    </div>
    {/foreach}
    {else}
    <div class="info-message">该插件暂无可配置项</div>
    {/if}
</form>
